import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wallet_utils/base_router_config.dart';
import 'package:wallet_utils/color.dart';
import 'package:wallet_utils/el_refresh.dart';
import 'package:wallet_utils/event_bus_utils.dart';
import 'package:wallet_utils/hopson_cash_ts.dart';
import 'package:wallet_utils/ht_appbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wallet_utils/ht_common_widgets.dart';
import 'package:wallet_utils/msg_event_utils.dart';
import 'package:wallet_utils/report_widget/click_widget.dart';
import 'package:wallet_utils/text_style.dart';
import '../../home/hxh_audit_details/view.dart';
import 'logic.dart';

class LoanDocPage extends StatelessWidget {
  final logic = Get.put(LoanDocLogic());
  final state = Get.find<LoanDocLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ColorManager.colorF4F5F6,
      appBar: htCommonAppbar(context, title: '贷款记录'),
    body: elRefresh(
    height: 50.w,
    refreshController: state.refreshController,
    enablePullUp: false,
    onRefresh: () async {
    logic.getUserOrder();
    },
      child: GetBuilder<LoanDocLogic>(builder: (logic) {
        return logic.orderList!.isNotEmpty ? Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            SizedBox(
              height: 12.w,
            ),
            MediaQuery.removePadding(
                context: context,
                removeTop: true,
                child: Container(
                  color: ColorManager.colorF4F5F6,
                  child: ListView.builder(
                    shrinkWrap: true,
                    itemCount:logic.orderList!.isNotEmpty?logic.orderList?.length:0,
                    physics: const NeverScrollableScrollPhysics(),
                    itemBuilder: ((context, index) {
                      return GestureDetector(
                        onTap: () {
logic.didClickAction(logic.orderList![index].auditStatus ?? 0, logic.orderList![index].orderStatus ?? 0, logic.orderList![index].orderNo??'0');

                        },
                        child: productItem(index),
                      );
                    }),
                  ),
                )),
          ],
        ):htEmptyDataWidget(
          title: "暂无贷款记录",
          image: 'images/user_loan_his.png',
        );
      }),
    ));
  }

  Container productItem(int index) {
    return Container(
      height: 100.w,
      margin: EdgeInsets.only(left: 16.w, bottom: 10.w, right: 16.w),
      decoration: BoxDecoration(
        color: ColorManager.colorFFFFFF,
        borderRadius: BorderRadius.all(Radius.circular(5.0)),
      ),
      child: Stack(
        children: [
          Container(
              margin: EdgeInsets.only(top: 0.w, left: 287.sp),
              child: Image.asset(
                logic.getTagImge(logic.orderList![index].auditStatus ?? 0, logic.orderList![index].orderStatus ?? 0),
                width: 60,
                height: 23,
                fit: BoxFit.contain,
              )),
          Container(
            margin: EdgeInsets.only(top: 18.w, left: 15.w),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Image.asset('images/hxh_logo.png',
                        width: 20.w, height: 20.h),
                    Container(
                        alignment: Alignment.center,
                        margin: EdgeInsets.only(top: 0.w, left: 5.w),
                        child: Text(
                          // logic.orderList![index].name
                          '恒小花',
                          style: TextStyleUtils.style000000(fontSize: 14.sp,fontWeight: Medium),
                        )),
                    Container(
                        alignment: Alignment.center,
                        margin: EdgeInsets.only(top: 0.w, left: 10.w),
                        child: Text(
                          logic.orderList![index].orderUpdateTimeStr ?? '',
                          style: TextStyleUtils.style999999(fontSize: 12.sp),
                        )),
                  ],
                ),
                SizedBox(
                  height: 10.w,
                ),
                logic.orderList![index].auditStatus !=120 ?Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Column(
                      children: [
                        Text(
                          "${logic.orderList![index].auditAmount !=null?(logic.orderList![index].auditAmount!/100).toStringAsFixed(2):'--'}元",
                          style: TextStyleUtils.style000000(
                            fontSize: 16.sp,
                            fontWeight: Medium,
                          ),
                        ),
                        Text(
                          '借款金额',
                          style: TextStyleUtils.style999999(fontSize: 12.sp),
                        )
                      ],
                    ),

                    Column(
                      children: [
                        Text(
                          "${logic.orderList![index].auditPeriodNum !=null ? logic.orderList![index].auditPeriodNum:'--'}个月",
                          style: TextStyleUtils.style000000(
                            fontSize: 18.sp,
                            fontWeight: Medium,
                          ),
                        ),
                        Text(
                          '借款时间',
                          style: TextStyleUtils.style999999(fontSize: 12.sp),
                        )
                      ],
                    ),

                    ClickWidget(
                      onTap: () {
                        logic.functionAction(logic.orderList![index].auditStatus ?? 0, logic.orderList![index].orderStatus ?? 0,logic.orderList![index].orderNo ?? '');
                      },
                      child: logic.getButtonTitle(logic.orderList![index].auditStatus ?? 0, logic.orderList![index].orderStatus ?? 0)!=''? Container(
                        height: 30.w,
                        width: 80.w,
                        padding: EdgeInsets.only(left: 19.w, right: 19.w),
                        alignment: const Alignment(0, 0),
                        margin: EdgeInsets.only(
                          right: 15.w,
                        ),
                        decoration: BoxDecoration(
                          color: ColorManager.color1D52FF,
                          //设置四周圆角 角度 这里的角度应该为 父Container height 的一半
                          borderRadius: BorderRadius.all(Radius.circular(15.0)),
                        ),
                        child: Text(
                          logic.getButtonTitle(logic.orderList![index].auditStatus ?? 0, logic.orderList![index].orderStatus ?? 0),
                          style: TextStyleUtils.styleFFFFFF(fontSize: 12.w),
                        ),
                      ):Container(),
                    ),

                  ],
                ):
                Container(
                    margin: EdgeInsets.only(top: 10.w),
                  child: Text(
                    "${logic.orderList![index].auditRejectReasons !=null ? logic.orderList![index].auditRejectReasons:'审核失败'}",
                      style: TextStyleUtils.style333333(fontSize: 14.sp),
                    )
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
